<template>
	<view :style="theme">
		<view v-if="indexShop == 0" class="hdList">
			<view v-for="(item, index) in list" :key="index" class="hdli" @click="jumps(item)">
				<view class="kuan">
					<image :src="item.showProjectPictures"></image>
				</view>
				<view class="hdWz limit-1-line">
					{{item.projectName}}
				</view>
			</view>
		</view>
		<view v-else>
			<view v-for="(item, index) in list" :key="index"  class="xmList">
				<view class="f32 c3 fwb mb4" style="width: 100%;">
					{{ item.name }}
				</view>
				<view class="card">
					<view v-for="(em, dex) in item.List" :key="dex" class="hdli" @click="jumps(em)">
						<view class="bj"></view>
						<view class="kuan">
							<image :src="em.showProjectPictures"></image>
						</view>
						<view class="hdWz limit-1-line">
							{{em.projectName}}
						</view>
					</view>
				</view>
				
			</view>
		</view>
		<view v-if="list.length === 0" class="no-order">
			<image :src="imgHost+'/default_nodata.png'"></image>
			<view>暂无项目～</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				indexShop: 0,
				type: 1
			}
		},
		onLoad(ops) {
			this.type = ops.type || 1
			this.indexShop = ops.indexShop || 0
			this.getList()
		},
		methods: {
			jump(url, params, a) {
				this.$app.jump(url, params, a);
			},
			jump2(url, params, a) {
				this.$app.jump2(url, params, a);
			},
			jump3(url, params, a) {
				this.$app.jump3(url, params, a);
			},
			jumps(item) {
				if(item.venueId) {
					this.$store.commit('setVenueName', item.venueName);
					this.$store.commit('setVenueId', item.venueId);
					if (this.type == 2) {
						this.jump3('/pages/venue/fieldArea?id=', item.projectId + '&name=' + item.projectName + '&peerNum=' + item
							.peerNum + '&type=' + this.type)
					} else {
						this.jump2('/pages/venue/fieldArea?id=', item.projectId + '&name=' + item.projectName + '&peerNum=' + item
							.peerNum + '&type=' + this.type)
					}
				} else {
					if (this.type == 2) {
						this.jump3('/pages/venue/fieldArea?id=', item.id + '&name=' + item.projectName + '&peerNum=' + item
							.peerNum + '&type=' + this.type)
					} else {
						this.jump2('/pages/venue/fieldArea?id=', item.id + '&name=' + item.projectName + '&peerNum=' + item
							.peerNum + '&type=' + this.type)
					}
				}
				
			},
			getList() {
				if (this.indexShop == 1) {
					this.$app.ajax({
						data: {
							param: {
								type: "0",
								status: '1'
							}
						},
						api: this.$api.getProjectb()
					}).then((res) => {
						if (res.errorCode === '000000') {
							let arr = res.recordList || []
							let dataArr = []
							arr.map((mapItem) => {
							      let index = dataArr.findIndex((item) => item.venueId === mapItem.venueId);
							      if (index === -1) {
							        dataArr.push({
									  name: mapItem.venueName,
							          venueId: mapItem.venueId,
							          List: [mapItem],
							        });
							      } else {
							        dataArr[index].List.push(mapItem);
							      }
							    });
							let newArr= dataArr;
							this.list = newArr
						}
					}).catch(() => {})
				} else {
					this.$app.ajax({
						data: {
							param: {
								venueId: this.venueId,
								type: "0",
								status: '1'
							}
						},
						api: this.$api.getProject()
					}).then((res) => {
						if (res.errorCode === '000000') {
							this.list = res.recordList || []
						}
					}).catch(() => {})
				}

			}
		}

	}
</script>
<style scoped lang="scss">
	.xmList {
		box-sizing: border-box;
		padding: 30rpx 30rpx 10rpx;
		background: #FFFFFF;
		margin-bottom: 24rpx;
		.card {
			display: flex;
			flex-wrap: wrap;
			box-sizing: border-box;
			.hdli {
				width: 22%;
				margin-right: 4%;
				border-radius: 20rpx;
				
				height: 190rpx;
				margin-bottom: 20rpx;
				display: flex;
				align-items: center;
				flex-direction: column;
				justify-content: center;
				text-align: center;
				position: relative;
			
				&:nth-child(4n) {
					margin-right: 0;
				}
				.bj {
					position: absolute;
					left: 0;
					top: 0;
					right: 0;
					bottom: 0;
					opacity: 0.2;
					background-color: $color;
					z-index: 0;
					display: block;
				}
			
				.kuan {
					width: 80rpx;
					margin: 0 15rpx;
					display: block;
					height: 80rpx;
					background-color: #fff;
					box-sizing: border-box;
					display: flex;
					justify-content: center;
					align-items: center;
			
					image {
						width: 50rpx;
						height: 50rpx;
					}
				}
			
				.hdWz {
					color: #333333;
					margin-top: 20rpx;
				}
			
				&.on {
					.kuan {
						border: none;
						background-color: $color;
					}
			
					.hdWz {
						color: $color;
					}
				}
			}
		}
		
	}

	.hdList {
		display: flex;
		flex-wrap: wrap;
		box-sizing: border-box;
		padding: 20rpx 30rpx;

		.hdli {
			width: 22%;
			margin-right: 4%;
			border-radius: 20rpx;
			height: 190rpx;
			margin-bottom: 20rpx;
			display: flex;
			align-items: center;
			flex-direction: column;
			justify-content: center;
			position: relative;
			text-align: center;
			background-color: #fff;

			&:nth-child(4n) {
				margin-right: 0;
			}
			.kuan {
				width: 80rpx;
				margin: 0 15rpx;
				display: block;
				height: 80rpx;
				background-color: #fff;
				box-sizing: border-box;
				display: flex;
				justify-content: center;
				align-items: center;

				image {
					width: 50rpx;
					height: 50rpx;
				}
			}

			.hdWz {
				color: #333333;
				margin-top: 20rpx;
			}

			&.on {
				.kuan {
					border: none;
					background-color: $color;
				}

				.hdWz {
					color: $color;
				}
			}
		}

	}
</style>